<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!--jquery库-->
    <script src="../js/jquery.min.js"></script>
    <!--bootstrap库-->
    <link href="../css/bootstrap.min.css" rel="stylesheet" />
    <script src="../js/bootstrap/bootstrap.min.js"></script>
    <!--[if lt IE 9]>
          <script src="../js/bootstrap/html5shiv.min.js"></script>
          <script src="../js/bootstrap/respond.min.js"></script>
        <![endif]-->
    <!--font-awesome字体库-->
    <link href="../css/font-awesome.min.css" rel="stylesheet" />
    <!--页面加载进度条-->
    <link href="../css/pace/dataurl.css" rel="stylesheet" />
    <script src="../js/pace/pace.min.js"></script>
    <!--jquery.hammer手势插件-->
    <script src="../js/jquery.hammer/hammer.min.js"></script>
    <script src="../js/jquery.hammer/jquery.hammer.js"></script>
    <!--平滑滚动到顶部库-->
    <script src="../js/jquery.scrolltopcontrol/scrolltopcontrol.js" type="text/javascript"></script>
    <!--主要写的jquery拓展方法-->
    <script src="../js/jquery.extend.js" type="text/javascript"></script>
    <!--主要写的css代码-->
    <link href="../css/default.css" rel="stylesheet" type="text/css" />
    <!--主要写的js代码-->
    <script src="../js/default.js" type="text/javascript"></script>

    <!-- artTemplate 模板引擎 -->
    <script src="../js/template-web.js" type="text/javascript"></script>

    <!-- 设置送检单位 -->
    <script src="../js/set-customer.js" type="text/javascript"></script>

    <title>产前血清学筛查</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html {
            height: 100%;
        }

        body {
            font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            font-size: 14px;
            line-height: 1.42857143;
            color: #333;
            background: #fff;
        }

        .field-row {
            margin: 4px;
        }

        .field-row>.field-item {
            display: inline-block;
            white-space: nowrap;
            margin-left: 10px;
        }

        .field-row>.field-item select {
            display: inline-block;
            white-space: nowrap;
            margin: 0;
            padding: 0;
            border-width: 1px;
            border-style: solid;
            overflow: hidden;
            vertical-align: middle;
            border-color: #AED0EA;
            background-color: #ffffff;
            min-width: 180px;
        }


        .field-row>.field-item>div.value {
            display: inline-block;
        }

        .field-row>.field-item>div.value>input {
            display: inline-block;
            width: 80px;
        }

        input {
            border-top: 0;
            border-left: 0;
            border-right: 0;
            border-bottom: 1px black solid;
            outline: none;
            height: 20px;
            line-height: 20px;
        }

        .head {
            padding-left: 10px;
            height: 28px;
            line-height: 28px;
            background: rgb(23, 134, 184);
            font-size: 10.5pt;
            color: #FFF;
        }

        .box-wrapper {
            width: 1000px;
            margin: 0 auto;
            overflow-x: hidden;
        }

        span.require {
            color: #f00;
        }

        .box {
            border: 1px solid #000;
        }

        input[type="checkbox"],
        input[type="radio"] {
            height: 20px;
            line-height: 20px;
            display: inline-block;
            margin: 6px 2px;
            vertical-align: bottom;
        }

        #otherDiseaseHistory {
            display: inline-block;
            width: 130px;
        }

        .coupon-box {
            height: 120px;
            text-align: center;
            line-height: 120px;
            border: 1px dashed #2e85b8;
            font-size: 24px;
            color: #cecece;
            margin: 30px 0 10px 0;
            cursor: pointer;
            background: #fff;
        }

        .coupon-item {
            width: 80%;
            box-shadow: 2px 2px 5px #f2f2f2, -2px -2px 5px #f2f2f2;
            border-bottom: 1px solid #eee;
            display: flex;
            margin: 10px auto;
            flex-direction: row;
        }

        .coupon-item .btn {
            display: block;
            margin: 10px;
            width: 60px;
            padding: 0;
            height: 28px;
            line-height: 28px;
            text-align: center;
            background: #45b4f5;
            color: #fff;
            /* outline: none; */
            border-color: transparent;
        }

        .coupon-item .content-wrapper {
            flex: 1;
            padding: 10px;
            line-height: 24px;
        }

        .coupon-item .content-wrapper .name {
            font-size: 14px;
            font-weight: 400;
            color: rgba(0, 0, 0, 0.85);
        }

        .coupon-item .content-wrapper .desc {
            font-size: 12px;
            margin-top: 4px;
            color: rgba(0, 0, 0, 0.55);
        }

        .search-box input {
            display: inline-block;
            flex: 1;
            height: 33px;
            line-height: 33px;
            padding-left: 6px;
            /* border-color: transparent; */
            outline: none;
            box-shadow: none;
            /* border: 0; */
            border: 1px solid #7bcdf8;
        }

        .search-box button {
            width: 80px;
            background: #7bcdf8;
            outline: none;
            border: 1px solid #7bcdf8;
            color: #fff;
        }

        .empty-coupon {
            text-align: center;
            line-height: 42px;
            height: 42px;
            font-size: 18px;
            color: rgba(0, 0, 0, 0.45);
        }

        .no-coupon {
            height: 33px;
            line-height: 33px;
            text-align: center;
            margin: 10px 0;
            border: 1px dashed #7bcdf8;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="box-wrapper">
        <div class="coupon-box" onclick="chooseCoupon()">
            选择免费券
        </div>
        <div class="box">
            <div class="head">送检单信息</div>
            <div class="field-row">
                <div class="field-item select">
                    <label for="customerCode">
                        <span class="require">*</span>采血医院：
                    </label>
                    <select value="" class="addressCounty" onchange="onAddressCountyChange(this.value)"></select>
                    <select name="customerCode" id="customerCode">
                    </select>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="doctorName">开单医生：</label>
                    <input type="text" id="doctorName">
                </div>
                <div class="field-item">
                    <label for="notes">备注：</label>
                    <input type="text" id="notes">
                </div>
            </div>
        </div>
        <div class="box">
            <div class="head">样本信息</div>
            <div class="field-row">
                <div class="field-item">
                    <label for="sampleType">样本类型：</label>
                    <input type="radio" name="sampleType" value="101">正常样本
                    <input type="radio" name="sampleType" value="102">重采样本
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="bloodDate">采样日期：</label>
                    <input type="date" id="bloodDate">
                </div>
            </div>
        </div>
        <div class="box">
            <div class="head">基本信息</div>
            <div class="field-row">
                <div class="field-item">
                    <label for="sampleName">姓名：</label>
                    <input type="text" id="sampleName">
                </div>
                <div class="field-item">
                    <label for="motherPhoneNum">联系电话：</label>
                    <input type="text" id="motherPhoneNum">
                </div>
                <div class="field-item">
                    <label for="idCard">身份证号：</label>
                    <input type="text" id="idCard">
                </div>

                <div class="field-item">
                    <label for="birthDate">生日</label>
                    <input type="date" name="birthDate" id="birthDate">
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="dnaMotherName">母亲姓名：</label>
                    <input type="text" id="dnaMotherName">
                </div>
                <div class="field-item">
                    <label for="dnaMotherIdCard">母亲身份证：</label>
                    <input type="text" name="dnaMotherIdCard" id="dnaMotherIdCard">
                </div>
                <div class="field-item">
                    <label for="motherPlace">母亲户籍：</label>
                    <input type="text" name="motherPlace" id="motherPlace">
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="dnaFatherName">父亲姓名：</label>
                    <input type="text" id="dnaFatherName">
                </div>
                <div class="field-item">
                    <label for="dnaFatherIdCard">父亲身份证号：</label>
                    <input type="text" id="dnaFatherIdCard">
                </div>
                <div class="field-item">
                    <label for="fatherPlace">父亲户籍：</label>
                    <input type="text" id="fatherPlace">
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="address">联系地址：</label>
                    <input type="text" id="address">
                </div>
            </div>
        </div>
        <div class="box">
            <div class="head">临床信息</div>
            <div class="field-row">
                <div class="field-item">
                    <label for="bodyWeight">体重：</label>
                    <input type="text" id="bodyWeight">
                    <span class="unit">KG</span>
                </div>
                <div class="field-item">
                    <label for="lmp">末次月经：</label>
                    <input type="date" id="lmp">
                </div>
                <div class="field-item">
                    <label for="fetusNum">胎儿个数：</label>
                    <input type="number" id="fetusNum">
                    <span class="unit">个</span>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="identicalTwins">同胎双生：</label>
                    <input type="radio" name="identicalTwins" value="1">是
                    <input type="radio" name="identicalTwins" value="0">否
                </div>
                <div class="field-item">
                    <label for="rule">是否规则：</label>
                    <input type="radio" name="rule" value="1">是
                    <input type="radio" name="rule" value="0">否
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="gestationalWeekFigure">孕周计算方式：</label>
                    <input type="radio" name="gestationalWeekFigure">末次月经
                    <input type="radio" name="gestationalWeekFigure">CRL
                    <input type="radio" name="gestationalWeekFigure">BPD
                    <input type="radio" name="gestationalWeekFigure">B超确认
                    <input type="radio" name="gestationalWeekFigure">HC
                    <input type="radio" name="gestationalWeekFigure">辅助生殖
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="btypeTime">B超时间：</label>
                    <input type="date" name="btypeTime" id="btypeTime">
                </div>
                <div class="field-item">
                    <label for="btypeGestationalWeek">B超孕周：</label>
                    <div class="value">
                        <input type="text" name="btypeGestationalWeek_week" id="btypeGestationalWeek_week">周
                        <input type="text" name="btypeGestationalWeek_day" id="btypeGestationalWeek_day">天
                    </div>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="lmpGestationalWeek">LMP孕周：</label>
                    <div class="value">
                        <input type="text" name="lmpGestationalWeek_week" id="lmpGestationalWeek_week">周
                        <input type="text" name="lmpGestationalWeek_day" id="lmpGestationalWeek_day">天
                    </div>
                </div>
                <div class="field-item">
                    <label for="assistGestationalWeek">辅助孕周：</label>
                    <div class="value">
                        <input type="text" name="assistGestationalWeek_week" id="assistGestationalWeek_week">周
                        <input type="text" name="assistGestationalWeek_day" id="assistGestationalWeek_day">天
                    </div>
                </div>
                <div class="field-item">
                    <label for="crlFigure">CRL：</label>
                    <input type="text" id="crlFigure">
                    <span class="unit">mm(双胎大值)</span>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="bpdFigure">BPD：</label>
                    <input type="text" id="bpdFigure">
                    <span class="unit">mm(双胎大值)</span>
                </div>
                <div class="field-item">
                    <label for="crlGestationalWeek">CRL孕周：</label>
                    <div class="value">
                        <input type="text" name="crlGestationalWeek_week" id="crlGestationalWeek_week">周
                        <input type="text" name="crlGestationalWeek_day" id="crlGestationalWeek_day">天
                    </div>
                </div>
                <div class="field-item">
                    <label for="realGestationalWeek">实际孕周：</label>
                    <div class="value">
                        <input type="text" name="realGestationalWeek_week" id="realGestationalWeek_week">周
                        <input type="text" name="realGestationalWeek_day" id="realGestationalWeek_day">天
                    </div>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="crl2Figure">CRL2：</label>
                    <input type="text" id="crl2Figure">
                    <span class="unit">mm(双胎大值)</span>
                </div>
                <div class="field-item">
                    <label for="bpd2Figure">BPD2：</label>
                    <input type="text" id="bpd2Figure">
                    <span class="unit">mm(双胎大值)</span>
                </div>
                <div class="field-item">
                    <label for="bpdGestationalWeek">BPD孕周：</label>
                    <div class="value">
                        <input type="text" name="bpdGestationalWeek_week" id="bpdGestationalWeek_week">周
                        <input type="text" name="bpdGestationalWeek_day" id="bpdGestationalWeek_day">天
                    </div>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="assistAge">辅助年龄：</label>
                    <input type="text" id="assistAge">
                </div>
                <div class="field-item">
                    <label for="assistAge">预产年龄：</label>
                    <input type="text" id="edd">
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="assistReproduction">辅助生殖方法：</label>
                    <select name="assistReproduction" id="assistReproduction">
                        <option value="">请选择</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                    </select>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="oocyteBirthday">赠卵者生日：</label>
                    <input type="date" id="oocyteBirthday">
                </div>
                <div class="field-item">
                    <label for="extractAge">提取年龄：</label>
                    <input type="number" id="extractAge">
                    <span class="unit">岁</span>
                </div>
                <div class="field-item">
                    <label for="implantationDate">植入日期：</label>
                    <input type="date" id="implantationDate">
                </div>
                <div class="field-item">
                    <label for="extractDate">提取日期：</label>
                    <input type="date" id="extractDate">
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="ntFigure">NT参与计算：</label>
                    <input type="radio" name="ntFigure" value="1">是
                    <input type="radio" name="ntFigure" value="0">否
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="nt1Value">NT1：</label>
                    <input type="text" id="nt1Value">
                    <span class="unit">mm</span>
                </div>
                <div class="field-item">
                    <label for="nt21Value">2NT1：</label>
                    <input type="text" id="nt21Value">
                    <span class="unit">mm</span>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="nt2Value">NT2：</label>
                    <input type="text" id="nt2Value">
                    <span class="unit">mm</span>
                </div>
                <div class="field-item">
                    <label for="nt22Value">2NT2：</label>
                    <input type="text" id="nt22Value">
                    <span class="unit">mm</span>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="nt3Value">NT3：</label>
                    <input type="text" id="nt3Value">
                    <span class="unit">mm</span>
                </div>
                <div class="field-item">
                    <label for="nt23Value">2NT3：</label>
                    <input type="text" id="nt23Value">
                    <span class="unit">mm</span>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="nt1AvgValue">NT1均值：</label>
                    <input type="text" id="nt1AvgValue">
                    <span class="unit">mm</span>
                </div>
                <div class="field-item">
                    <label for="nt2AvgValue">NT2均值：</label>
                    <input type="text" id="nt2AvgValue">
                    <span class="unit">mm</span>
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="smokingTag">是否吸烟：</label>
                    <input type="radio" name="smokingTag" value="1">是
                    <input type="radio" name="smokingTag" value="0">否
                </div>
                <div class="field-item">
                    <label for="diabetesByInsulin">是否胰岛素依赖性糖尿病：</label>
                    <input type="radio" name="diabetesByInsulin" value="1">是
                    <input type="radio" name="diabetesByInsulin" value="0">否
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="censusTag">户籍：</label>
                    <input type="radio" name="censusTag" value="1">省内
                    <input type="radio" name="censusTag" value="0">省外
                </div>
                <div class="field-item">
                    <label for="identityInfo">同身份证信息：</label>
                    <input type="text" id="identityInfo">
                </div>
                <div class="field-item">
                    <label for="race">种族：</label>
                    <input type="radio" name="race" value="0">默认
                    <input type="radio" name="race" value="1">加勒比海人
                    <input type="radio" name="race" value="2">高加索
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <input type="checkbox" name="uniteTag" id="uniteTag" value="1">
                    <label for="uniteTag">是否联合</label>
                </div>
                <div class="field-item">
                    <input type="radio" name="uniteValue" value="0">中孕三联
                    <input type="radio" name="uniteValue" value="1">中孕二联
                    <input type="radio" name="uniteValue" value="2">早孕三联
                    <input type="radio" name="uniteValue" value="3">早孕二联+NT
                    <label for="uniteValue" style="text-indent:-9999px;">联合方式</label>
                </div>
                <div class="field-item">
                    <input type="checkbox" name="screeningTag" id="screeningTag" value="1">
                    <label for="screeningTag">是否筛查</label>
                </div>
                <div class="field-item">
                    <input type="text" name="screeningReason" id="screeningReason" placeholder="不筛查原因">
                    <label for="screeningReason" style="color:#fff;text-indent:-9999px;">不筛查原因</label>
                </div>

            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="personalHistory">已往病史：</label>
                    <input type="checkbox" name="personalHistory" value="NTD">NTD
                    <input type="checkbox" name="personalHistory" value="N21">N21
                    <input type="checkbox" name="personalHistory" value="T18">T18
                    <input type="checkbox" name="personalHistory" value="T13">T13
                    <input type="checkbox" name="personalHistory" value="CdLS">CdLS
                    <input type="checkbox" name="personalHistory" value="SLOS">SLOS
                    <input type="checkbox" name="personalHistory" value="TS">TS
                    <input type="checkbox" name="personalHistory" value="TR">TR
                    <input type="checkbox" name="personalHistory" value="自然流产史">自然流产史
                    <input type="checkbox" name="personalHistory" value="胎儿畸形">胎儿畸形
                    <input type="checkbox" name="personalHistory" value="死胎">死胎
                    <input type="checkbox" name="personalHistory" value="死产">死产
                    <input type="checkbox" name="personalHistory" value="新生儿死产">新生儿死产
                    <input type="checkbox" name="personalHistory" value="其他">其他
                    <input type="text" id="otherDiseaseHistory">
                </div>
            </div>
            <div class="field-row">
                <div class="field-item">
                    <label for="abnormalType">异常类型：</label>
                    <select id="abnormalType">
                        <option value="">请选择</option>
                        <option value="1">1</option>
                        <option value="1">2</option>
                    </select>
                </div>
                <div class="field-item">
                    <label for="patientNum">病历号：</label>
                    <input type="text" id="patientNum">
                </div>
            </div>
        </div>
        <div style="width:220px; margin: 30px auto;">
            <button onclick="save();" style="width: 120px; height: 33px; border-radius: 2px; border-radius: 4px; background: rgb(23,134,184); color: #fff; outline: none; border-color: transparent;">保存</button>
        </div>
    </div>
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        免费券列表
                    </h4>
                </div>
                <div class="modal-body">
                    <div class="search-box" style='display:flex;flex-direction:row'>
                        <input type="text" placeholder="请输入证件号码" id="coupon-kw" style="display:inline-block;flex:1">
                        <button onclick="searchCoupons()">搜索</button>
                    </div>
                    <div class="no-coupon">
                        不使用免费券
                    </div>
                    <div class="empty-coupon">
                        没有免费券
                    </div>
                    <div class="coupon-list">
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
    </div>
    <i class="t-product-value" style="display: none;">BS0001</i>）
        <!-- /.modal -->
        <script>
            var isEdit = false
            var sampleBaseId
            //获取URL参数
            function getJsonFromUrl() {
                var query = location.search.substr(1);
                var result = {};
                query.split("&").forEach(function (part) {
                    var item = part.split("=");
                    result[item[0]] = decodeURIComponent(item[1]);
                });
                return result;
            }
            isEdit = getJsonFromUrl().isEdit
            //获取当前登录用户信息
            $(document).ready(function () {
                $.ajax({
                    method: 'POST',
                    url: '/csfy/intf.do',
                    data: { method: 'getLoginUserInfo' },
                    success: res => {
                        if (res.code == 10086) {
//                            window.location.href = "/csfy/index.do"
                            alert("请重新登录！");
                        } else {
                            if (res.code == 200) {
                                $(".username").html(res.rows.userName);
                            }
                        }
                    }
                })
            })


            var elements = {}//提交服务器的字段属性
            var name = ''
            var radios = $(".box input[type='radio']")
            radios.map((index, ele) => {
                var tmpName = $(ele).attr("name");
                var isRequire = $(ele).parent().find(".require").length > 0
                var fieldName = $(ele).parent().find("label").text()
                if (fieldName.indexOf("*") != -1) {
                    fieldName = fieldName.substr(fieldName.indexOf("*") + 1, fieldName.length)
                }
                fieldName = fieldName.replace("：", "")

                if (name != tmpName) {
                    name = tmpName
                    elements[name] = { type: "radio", require: isRequire, fieldName }
                }
            })

            var checkboxs = $(".box input[type='checkbox']")
            checkboxs.map((index, ele) => {
                var tmpName = $(ele).attr("name");
                var isRequire = $(ele).parent().find(".require").length > 0
                var fieldName = $(ele).parent().find("label").text()
                if (fieldName.indexOf("*") != -1) {
                    fieldName = fieldName.substr(fieldName.indexOf("*") + 1, fieldName.length)
                }
                fieldName = fieldName.replace("：", "")
                if (name != tmpName) {
                    name = tmpName
                    elements[name] = { type: "checkbox", require: isRequire, fieldName }
                }
            })

            var otherInputs = $('.box input:not(:checkbox):not(:radio)')
            otherInputs.map((index, ele) => {
                var tmpName = $(ele).attr("id")
                if (tmpName.indexOf("_") != -1) {
                    tmpName = tmpName.split("_")[0]
                }
                var isRequire = $(ele).parent().find(".require").length > 0
                var fieldName = $(ele).parent().find("label").text()
                if (!fieldName) {
                    fieldName = $(ele).parent().siblings("label").text()
                }
                if (fieldName.indexOf("*") != -1) {
                    fieldName = fieldName.substr(fieldName.indexOf("*") + 1, fieldName.length)
                }
                fieldName = fieldName.replace("：", "")
                if (name != tmpName) {
                    name = tmpName
                    elements[name] = { type: "text", require: isRequire, fieldName }
                }
            })

            var selects = $(".box select")
            selects.map((index, ele) => {
                var tmpName = $(ele).attr("id")
                var isRequire = $(ele).parent().find(".require").length > 0
                var fieldName = $(ele).parent().find("label").text()
                if (fieldName.indexOf("*") != -1) {
                    fieldName = fieldName.substr(fieldName.indexOf("*") + 1, fieldName.length)
                }
                fieldName = fieldName.replace("：", "")
                if (name != tmpName) {
                    name = tmpName
                    elements[name] = { type: "select", require: isRequire, fieldName }
                }
            })

            var params = {} //提交到服务器的参数
            $(".box select").change(function () {
                var key = $(this).attr("id")
                var value = $(this).val()
                if (!value || value.length == 0) {
                    delete params[key]
                } else {
                    params[key] = value
                }
            })

            function radioOrCheckboxValueChange() {
                var key = $(this).attr("name")
                var value = undefined;
                if ($(this).attr('type') === 'checkbox') {
                    value = params[key]
                    var valueSplit = []
                    if (value && value.length > 0) {
                        valueSplit = value.split(",")
                    }
                    var v = $(this).val()
                    if ($(this).is(':checked')) {
                        valueSplit.push(v)
                    } else {
                        for (var index in valueSplit) {
                            if (valueSplit[index] == v) {
                                valueSplit.splice(index, 1)
                                break;
                            }
                        }
                    }
                    value = valueSplit.join(",")
                } else {
                    value = $(this).val()
                }
                if (value === undefined || value == "" || (value && value.length == 0)) {
                    delete params[key]
                } else {
                    params[key] = value
                }
            }

            function onInputValueChange() {
                var key = $(this).attr("id")
                var value = $(this).val()
                if (key.indexOf("_") == -1) {
                    if (!value || value.length == 0) {
                        delete params[key]
                    } else {
                        params[key] = value
                    }
                } else {
                    key = key.split("_")[0]
                    //孕周
                    var week = $("#" + key + "_week").val() || ""
                    var day = $("#" + key + "_day").val() || ""
                    if (!week && !day) {
                        delete params[key]
                    } else {
                        params[key] = week + "W+" + day
                    }
                }
            }
            $(".box input[type='radio']").change(radioOrCheckboxValueChange)
            $(".box input[type='checkbox']").change(radioOrCheckboxValueChange)
            $('.box input:not(:checkbox):not(:radio)').on("input", onInputValueChange)

            params.productName = '产前血清学筛查';
            params.productCode = 'BS0001';

            function save() {
                //设置模板文件路径，对应前端工作平台1.0的模板服务器路径
                params.fileVer = "temp/sample1.jsp"
                for (var key in elements) {
                    if (elements[key].require && !params[key]) {
                        alert("请输入" + elements[key].fieldName)
                        return false
                    }
                }
                if (couponNum) {
                    params.couponNum = couponNum
                }
                $.ajax({
                    type: 'POST',
                    data: {
                        method: isEdit ? 'updateSampleBaseBySampleBaseId' : 'createSampleBase',
                        ...params,
                        sampleBaseId: isEdit ? sampleBaseId : undefined
                    },
                    url: '/csfy/intf.do',
                    error: function (e) {
                        alert("操作失败")
                    },
                    success: function (res) {
                        if (res && res.code == 200) {
                            alert(isEdit ? "修改送检单成功" : "保存送检单成功");
                            if (!isEdit)
                                window.location.href = window.location.pathname;
                            else
                                sessionStorage.setItem("sampleEditSuccess", "true");
                        } else if (res) {
                            alert(res.msg ? res.msg : "操作失败")
                        }
                    }
                })
            }
            //使用优惠券
            var couponNum = '';

            //不使用优惠券
            $(".no-coupon").click(function () {
                $("#dnaMotherIdCard").removeAttr('disabled');
                $("#sampleName").removeAttr('disabled');
                $('#myModal').modal('hide');
                couponNum = '';
                $('.coupon-box').html('选择免费券');
            });

            function useCoupon(num) {
                //优惠券对应的身份证号码
                var id = $("#coupon-kw").val();
                //设置优惠券对应的身份证
                $("#idCard").val(id);
                //设置身份证输入框不可编辑
                $("#idCard").attr('disabled', 'disabled');

                //使用优惠券姓名
                $("#sampleName").val(sampleName);
                $("#sampleName").attr('disabled', 'disabled');

                $('#myModal').modal('hide');
                $('.coupon-box').html('免费券码：' + (num ? num : ''));

                //重置搜索列表
                $("#coupon-kw").val('');
                $(".coupon-list").html('');
                $(".empty-coupon").hide();

                couponNum = num;
            }

            //TODO 根据证件搜索优惠券
            function searchCoupons() {
                var id = $("#coupon-kw").val();
                if (id) {
                    $.ajax({
                        method: 'POST',
                        url: '/csfy/intf.do',
                        data: {
                            method: 'getDetailPresonInfo',
                            id
                        },
                        success: function (res) {
                            console.log(res)
                            var couponList = '';
                            sampleName = res.rows.name;
                            $(".coupon-list").html('');
                            $(".empty-coupon").html('正在搜索...');
                            if (res && res.code == 200) {
                                var couponInfos = (res.rows && res.rows.couponInfos) || [];
                                if (couponInfos.length > 0) {
                                    var mData = {};
                                    mData.rows = couponInfos;
                                    var html = template('coupon-list', mData);
                                    $(".coupon-list").html(html);
                                    $(".empty-coupon").hide();
                                } else {
                                    $(".empty-coupon").html('未找到当前证件名下的免费券');
                                }
                            } else {
                                $(".empty-coupon").html('未找到当前证件名下的免费券');
                            }
                        }
                    });
                } else {
                    $(".coupon-list").html('');
                    $(".empty-coupon").show();
                    $(".empty-coupon").html('没有找到免费券');
                }
            }
            //选择使用优惠券
            function chooseCoupon() {
                $('#myModal').modal('show');
            }

            //isEdit=true 编辑
            if (isEdit) {
                var obj = undefined;
                try { obj = JSON.parse(sessionStorage.getItem("sampleInfos")); } catch (err) { }
                if (obj) {
                    sampleBaseId = obj.sampleBaseId
                    Object.keys(obj).map(key => {
                        if (obj[key]) {
                            var element = elements[key];
                            if (element) {
                                params[key] = obj[key]
                                if (element.type == "checkbox") {
                                    $("input[type=checkbox][name=" + element.fieldName + "][value=" + obj[key] + "]").attr("checked", "checked")
                                } else if (element.type == "radio") {
                                    $("input[type=radio][name=" + element.fieldName + "][value=" + obj[key] + "]").attr("checked", "checked")
                                } else {
                                    $("#" + key).val(obj[key])
                                }
                            }
                        }
                    })
                }
            } 
        </script>
        <!-- 优惠券列表渲染 -->
        <script id="coupon-list" type="text/html">
            {{each rows item i}}
                <div class="coupon-item">
                    <div class="content-wrapper">
                        <div class="name">{{item.couponName}}</div>
                        <div class="desc">{{item.couponDesc}}</div>
                    </div>
                    {{if item.productCode == 'BS0001' && item.status == '1'}}
                        <button class="btn btn-primary" onclick="useCoupon('{{item.couponNum}}')">使用</button>
                    {{/if}}
                    {{if item.productCode != 'BS0001' || (item.productCode == 'BS0001' && item.status != '1')}}
                        <button class="btn btn-disbled" disabled>不可用</button>
                    {{/if}}
                </div>
            {{/each}}
        </script>
</body>

</html>